from src.application.user.exceptions import UserIdNotExist
from src.application.user.interfaces import UserRepo
from src.domain.user.aggregates import UserAggregate
from src.domain.user.value_objects import TelegramUserId


class UserRepoMock(UserRepo):
    def __init__(self) -> None:
        self.users: dict[TelegramUserId, UserAggregate] = dict()

    async def acquire_user_by_id(self, user_tg_id: TelegramUserId) -> UserAggregate:
        if user_tg_id not in self.users:
            raise UserIdNotExist(user_tg_id.value)
        return self.users[user_tg_id]

    async def create_user(self, user: UserAggregate) -> None:
        self.users[user.tg_id] = user

    async def update_user(self, user: UserAggregate) -> None:
        self.users[user.tg_id] = user

    async def check_user_exists(self, user_tg_id: TelegramUserId) -> bool:
        return user_tg_id in self.users
